package ONLINE_EXAM;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Inet4Address;
import java.util.Deque;
import java.util.LinkedList;

public class shell {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str ;
        while ((str= br.readLine())!= null){
            int count = Integer.valueOf(str);
            String string = br.readLine();
            String[] strings = string.split(" ");
            //全部存入deque
            Deque deque = new LinkedList();
            for (String s:strings){
                deque.addLast(Integer.valueOf(s));
            }

            StringBuffer sb = new StringBuffer();

            while (deque != null){
                int first = Integer.valueOf(deque.getFirst().toString());
                int last = Integer.valueOf(deque.getLast().toString());
                if(first < last){
                    deque.removeFirst();
                    sb.append(first);
                }else if (first > last){
                    deque.removeLast();
                    sb.append(last);
                }else {
                    if (deque.size()==1){
                        sb.append(first);
                    }else {
                        deque.removeFirst();
                        deque.removeLast();
                        if (Integer.valueOf(deque.getFirst().toString()) >  Integer.valueOf(deque.getLast().toString())){
                            deque.addFirst(first);
                            sb.append(last);
                        }else {
                            deque.addFirst(last);
                            sb.append(first);
                        }
                    }

                }
            }

            System.out.println(sb.toString());

        }
    }
}
